﻿//-------------------------------------------------------------------------------------------------------------------------------------
// Copyright (C) 2005 greatelsoft.com All Rights Reserved
//-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Pub.Class;
using GTS.MiniBox.Entity;

namespace GTS.MiniBox.Helper {
    public partial class BusinessReportInfoHelper {
        /// <summary>
        /// 批次缓存多少秒 x 5
        /// </summary>
        public static int cacheSeconds = 1440;

        public static IList<BusinessReportInfo> SelectByTime(string dbkey, string sPCode, int cstCode, int type, int channelID, string begin, string end) {
            string cacheNameKey = "GTS.MiniBox.SelectBusinessReportInfoCache_SelectBusinessReportInfoBy_{0}_{1}_{2}_{3}_{4}_{5}".FormatWith(sPCode, cstCode, type, channelID, begin, end);
            return Cache2.Get<IList<BusinessReportInfo>>(cacheNameKey, cacheSeconds, () => {
                DbParameter[] dbparam = new DbParameter[]{
                    Data.MakeInParam("@SPCode", (DbType)SqlDbType.VarChar, 20,sPCode),
                    Data.MakeInParam("@CstCode", (DbType)SqlDbType.Int, 4,cstCode),
                    Data.MakeInParam("@Type", (DbType)SqlDbType.Int, 4,type),
                    Data.MakeInParam("@ChannelID", (DbType)SqlDbType.Int, 4,channelID),
                    Data.MakeInParam("@Begin", (DbType)SqlDbType.VarChar, 10,begin),
                    Data.MakeInParam("@End", (DbType)SqlDbType.VarChar, 10,end)
                };
                return Data.Pool(dbkey).GetDataTable("report_BusinessReport", dbparam).ToList<BusinessReportInfo>();
            });
        }

        /// <summary>
        /// 缺帐时间
        /// </summary>
        public static IList<BusinessReportInfo> SelectMissTime(string dbkey, string begin, string end, string sPCode) {
            string cacheNameKey = "GTS.MiniBox.SelectBusinessReportInfoCache_SelectMissTime_{0}_{1}_{2}".FormatWith(begin, end, sPCode);
            return Cache2.Get<IList<BusinessReportInfo>>(cacheNameKey, cacheSeconds, () => {
                DbParameter[] dbparam = new DbParameter[]{
                    Data.MakeInParam("@Begin", (DbType)SqlDbType.VarChar, 10,begin),
                    Data.MakeInParam("@End", (DbType)SqlDbType.VarChar, 10,end),
                    Data.MakeInParam("@SPCode", (DbType)SqlDbType.VarChar, 20,sPCode)
                };
                return Data.Pool(dbkey).GetDataTable("report_BusinessReportMissBySP", dbparam).ToList<BusinessReportInfo>();
            });
        }

        public static void ClearCache() {
            Cache2.RemoveByPattern("GTS.MiniBox.SelectBusinessReportInfoCache_(.+?)");
        }
    }
}

